﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel; 
namespace WPFExcelReport
{
    public partial class TSSD0013
    {
      
        
        public TSSD0013()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            MV = new VSDDAT();
            DataContext = MV;
            SDSA = "0013"; 
            InitializeComponent();  
        } 
      
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)   return;
            base.Window_Loaded(sender, e);
             Load();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwKEY = dwMaster;
        }
        public void Load()
        {
            if (SDSA.Trim().Length == 0)
                return;
            dwData = ((VSDDAT)MV).SetData.Tables["SDDAT"].NewRow();
            dwData["SDSA"] = SDSA;
            dwData["SDKEY"] = " AND SDKEY LIKE '%" + LANG + "'";
            SResult = ((VSDDAT)MV).QuerySDDAT(dwData, Convert.ToInt16(SDSA));
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["SDES"] = Helpers.Helper.Convert8859P1ToGB2312(row["SDES"].ToString().Trim()); 
                row["DES"] = Helpers.Helper.Convert8859P1ToGB2312(row["DES"].ToString().Trim()); 
            }
            MergeData(SResult, false);
        }
        public void Locate()
        {
            vwMaster.View.MoveCurrentTo(-1);
            var query = from DataRow row in TBMain.AsEnumerable()
                        where row["KEY"].ToString().Trim() == KEY.Trim()
                        select row;
            foreach (DataRow row in query)
            {
                int idx = TBMain.Rows.IndexOf(row);
                vwMaster.View.MoveCurrentToPosition(idx);
                break;
            }
        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                Load();
            }
            else
            {
                VICC_WFEVENTS.SVWF.SD02(RUNID, SDSA);
            }
            //base.ManageCommand(sender, e);
        }

        private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            vwMaster.View.MoveCurrentTo(-1);
        }
    }
}
